from tools_algorithm import *


class Solution:
    def largestSquareArea(
        self, bottomLeft: List[List[int]], topRight: List[List[int]]
    ) -> int:

        def f(a, b, c, d):
            return max(0, min(b, d) - max(a, c))

        n = len(bottomLeft)
        ans = 0
        for i in range(n):
            bi, ti = bottomLeft[i], topRight[i]
            for j in range(i + 1, n):
                bj, tj = bottomLeft[j], topRight[j]
                vx = f(bi[0], ti[0], bj[0], tj[0])
                vy = f(bi[1], ti[1], bj[1], tj[1])
                if vx > 0 and vy > 0:
                    v = min(vx, vy)
                    ans = max(ans, v * v)
        return ans


s = Solution()
print(s.largestSquareArea([[1, 1], [2, 2], [3, 1]], [[3, 3], [4, 4], [6, 6]]))
